package com.ruoyi.project.anfang.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.anfang.domain.GongGao;
import com.ruoyi.project.anfang.service.IGongGaoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 公告管理Controller
 * 
 * @author chendg
 * @date 2025-04-15
 */
@Api(tags = "后端管理/公告管理")
@RestController
@RequestMapping("/anfang/gonggao")
public class GongGaoController extends BaseController
{
    @Autowired
    private IGongGaoService gongGaoService;

    /**
     * 查询公告管理列表
     */
//    @PreAuthorize("@ss.hasPermi('anfang:gonggao:list')")
    @GetMapping("/list")
    @ApiOperation("公告管理--列表")
    public TableDataInfo list(GongGao gongGao)
    {
        startPage();
        List<GongGao> list = gongGaoService.selectGongGaoList(gongGao);
        return getDataTable(list);
    }

    /**
     * 导出公告管理列表
     */
//    @PreAuthorize("@ss.hasPermi('anfang:gonggao:export')")
    @Log(title = "公告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("公告管理--导出")
    public void export(HttpServletResponse response, GongGao gongGao)
    {
        List<GongGao> list = gongGaoService.selectGongGaoList(gongGao);
        ExcelUtil<GongGao> util = new ExcelUtil<GongGao>(GongGao.class);
        util.exportExcel(response, list, "公告管理数据");
    }

    /**
     * 获取公告管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('anfang:gonggao:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("公告管理--详情")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gongGaoService.selectGongGaoById(id));
    }

    /**
     * 新增公告管理
     */
//    @PreAuthorize("@ss.hasPermi('anfang:gonggao:add')")
    @Log(title = "公告管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("公告管理--添加")
    public AjaxResult add(@RequestBody GongGao gongGao)
    {
        return toAjax(gongGaoService.insertGongGao(gongGao));
    }

    /**
     * 修改公告管理
     */
//    @PreAuthorize("@ss.hasPermi('anfang:gonggao:edit')")
    @Log(title = "公告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("公告管理--修改")
    public AjaxResult edit(@RequestBody GongGao gongGao)
    {
        return toAjax(gongGaoService.updateGongGao(gongGao));
    }

    /**
     * 删除公告管理
     */
//    @PreAuthorize("@ss.hasPermi('anfang:gonggao:remove')")
    @Log(title = "公告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("公告管理--删除")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gongGaoService.deleteGongGaoByIds(ids));
    }
}
